﻿using System;

namespace diantou.web.management
{
    /// <summary>
    /// 编辑课程
    /// </summary>
    [fastCSharp.code.cSharp.webView(IsPage = false, IsPool = true)]
    partial class courseEdit : permissionView<courseEdit>
    {
        /// <summary>
        /// 教程
        /// </summary>
        [fastCSharp.emit.webView.clearMember]
        private diantou.dataAccess.tutorial tutorial;
        /// <summary>
        /// 课程
        /// </summary>
        [fastCSharp.emit.webView.clearMember]
        private diantou.dataAccess.course course;
        /// <summary>
        /// 当前编辑课程分页
        /// </summary>
        private diantou.dataAccess.coursePage coursePage
        {
            get { return diantou.dataAccess.coursePage.NullPage;}
        }
        /// <summary>
        /// 分页问题
        /// </summary>
        private diantou.dataAccess.problem pageProblem;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="courseId"></param>
        /// <param name="tutorialId"></param>
        /// <returns></returns>
        private bool loadView(int courseId, int tutorialId)
        {
            if ((currentUser.Permission & dataModel.user.permission.TutorialEditor) != 0)
            {
                if (courseId == 0)
                {
                    tutorial = diantou.dataAccess.clientCache.Tutorial[tutorialId];
                    if (tutorial != null && (currentUser.Permission == dataModel.user.permission.Admin || tutorial.UserId == currentUser.Id))
                    {
                        course = new diantou.dataAccess.course { SortId = diantou.dataAccess.tcpCall.course.getNextSortId(tutorialId) };
                    }
                }
                else
                {
                    course = diantou.dataAccess.tcpCall.course.Get(courseId);
                    if (course != null)
                    {
                        tutorial = diantou.dataAccess.clientCache.Tutorial[course.TutorialId];
                        if (tutorial == null || (currentUser.Permission != dataModel.user.permission.Admin && tutorial.UserId != currentUser.Id)) course = null;
                    }
                }
                if (course != null) return true;
            }
            tutorial = null;
            AjaxResponse(new fastCSharp.code.cSharp.webView.errorPath { ErrorPath = currentUser.Path.NewFocus });
            return false;
        }
    }
}
